﻿using System.ComponentModel;
using System.Windows.Forms;
using Slippor.Common.PluginFramework;
using Slippor.Douban.Radio.Share;
using System;

namespace SinaWeiboPlugin
{
    [Description("新浪微博插件")]
    [DisplayName("新浪微博")]
    [Author("拖鞋不脱")]
    [Version(typeof(SinaWeiboVersion), SinaWeiboPlugin.Version)]
    [PluginCategory(PluginCategory.Other)]
    [Config(typeof(SinaWeiboConfig))]
    public class SinaWeiboPlugin : SharePlugin
    {
        public const String Version = "2.0.1.0";

        public SinaWeiboPlugin()
        {
            _sharer = new SinaWeiboSharer(this);
            Loaded += new System.EventHandler(SinaWeiboPlugin_Loaded);
            UnLoaded += new System.EventHandler(SinaWeiboPlugin_UnLoaded);
        }

        private const int _command = 10777;
        internal void RegHotkey()
        {
            var hotkeyService = (IHotkeyService)_application.GetService(typeof(IHotkeyService));
            if (hotkeyService != null)
            {
                hotkeyService.RegHotkey(_command, _sharer);
            }
        }

        internal void UnRegHotkey()
        {
            var hotkeyService = (IHotkeyService)_application.GetService(typeof(IHotkeyService));
            if (hotkeyService != null)
            {
                hotkeyService.RemoveHotkey(_command);
            }
        }

        private void SinaWeiboPlugin_UnLoaded(object sender, System.EventArgs e)
        {
            UnRegHotkey();
        }

        private  void SinaWeiboPlugin_Loaded(object sender, System.EventArgs e)
        {
            RegHotkey();
        }

        private static SinaWeiboSharer _sharer;
        protected override ISharer Sharer
        {
            get { return _sharer; }
        }
    }
}